package com.probiz.estoresa.order.web.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.order.OrderExpress;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.order.service.OrderExpressManager;
import com.probiz.estore.system.service.ShippingMethodManager;

public class OrderExpressController extends GenericStoreAdminController<OrderExpress> {
    private OrderExpressManager orderExpressManager ;
    private ShippingMethodManager  shippingMethodManager;

    public void setOrderExpressManager(OrderExpressManager inMgr) {
        this.orderExpressManager = inMgr;
    }

    
	public void setShippingMethodManager(ShippingMethodManager shippingMethodManager) {
		this.shippingMethodManager = shippingMethodManager;
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(OrderExpress entity) {
		return entity.getOrderExpressName();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.BaseController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = orderExpressManager;
	}
	
	@Override
	protected Map<String,String> getSortMap(){
		Map<String,String> sortMap = new HashMap<String,String>();
		sortMap.put("1", "convert_gbk(orderExpressName)");
		sortMap.put("2", "sortOrder");
		sortMap.put("3", "status*-1"); //激活的在前面
		sortMap.put("4", "createTime");
		sortMap.put("5", "updateTime");
		return sortMap;
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#preSave(javax.servlet.http.HttpServletRequest,
	 *      java.lang.Object, org.springframework.validation.BindException)
	 */
	@Override
	protected void preSave(HttpServletRequest request, OrderExpress entity, BindException errors) {
	}

	protected void onShowForm(HttpServletRequest request, ModelAndView mv){
		mv.addObject("shippingMethodList",shippingMethodManager.listAllActive());
	}
}
